package com.example.week10_spring_security.repo;

import com.example.week10_spring_security.entity.Goods;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface GoodsRepo extends JpaRepository<Goods,Long>, JpaSpecificationExecutor<Goods> {

    @Query(value = "select * from goods where id in (select goods_id from goods_suppliers where suppliers_id = ?1)",nativeQuery = true)
    List<Goods> findBySupplierId(Long id);


    @Query(value = "select * from goods where name like CONCAT('%',:name,'%') and price between :min and :max",nativeQuery = true)
    List<Goods> findByNameContainingAndPriceBetween(@Param("name") String name, @Param("min") Double minPrice,@Param("max") Double maxPrice);
}
